package testcase.app;


import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import api.app.GetAPIAccountInfo2;
import common.Host;
import common.TestData;


 /**
  * 帮忙医APP登录GetAPIAccountInfo2接口测试用例
  * @author lipeng
  *
  */
public class TestGetAPIAccountInfo2
{
	 /**
	  * 帮忙医APP登录GetAPIAccountInfo2接口测试环境数据驱动
	  * @return 测试数据
	  * @throws Exception
	  */
     @DataProvider (name="Test")
     public static String[][] testGetAPIAccountInfo2DataProvider() throws Exception{
    	 Host.setup("Test");
    	 TestData td = new TestData("app/TestGetAPIAccountInfo2.xml");
    	 return td.getParam();
     }
     
     /**
      * 帮忙医APP登录GetAPIAccountInfo2接口生产环境数据驱动
      * @return 测试数据
     * @throws Exception 
      */
     @DataProvider(name="Prod")
     public static String[][] prodGetAPIAccountInfo2DataProvider() throws Exception
     {
    	 Host.setup("Prod");
    	 TestData tData=new TestData("app/TestGetAPIAccountInfo2.xml");
    	 return tData.getParam();
     }
     
     /**
      * 帮忙医APP登录GetAPIAccountInfo2接口
      * @param caseName  -用例名称
      * @param account   -用户名
      * @param password  -密码 
      * @throws Exception
      */
     @Test (dataProvider = "Test",groups={"Test"})
     public void testGetAPIAccountInfo2TestCase(String caseName,String account,String password)throws Exception{
    	 //调用接口并将接口返回数据转换成json格式
		String result  = GetAPIAccountInfo2.post(account, password);
		JSONObject jsonResult;
		if(result==null || result.isEmpty()){
			jsonResult = null;
		}
		else {
			jsonResult = new JSONObject(result);
		}
		
		//设置检查点
		String checkpoint;
		switch (caseName) {
		case "LoginSuccess":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Success");	//接口返回状态为Success
			break;
		case "PasswordError":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Fail");	//接口返回状态为Fail
			break;
		case "UserAccountError":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Fail");	//接口返回状态为Fail
			break;
		case "UserAccountNull":	
			Assert.assertTrue(result.isEmpty());	//接口返回是否为空
			break;
		case "PasswordNull":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Fail");	//接口返回状态为Fail
			break;
		default:
			break;
		}
	}
     
     /**
      * 帮忙医APP登录GetAPIAccountInfo2接口生产环境测试用例
      * @param caseName
      * @param account
      * @param password
      * @throws Exception
      */
     @Test(dataProvider="Prod",groups="Prod")
     public void prodGetAPIAccountInfo2TestCase(String caseName,String account,String password) throws Exception
     {
    	 //调用接口并将接口返回数据转换成json格式
 		String result  = GetAPIAccountInfo2.post(account, password);
 		JSONObject jsonResult;
 		if(result==null || result.isEmpty()){
 			jsonResult = null;
 		}
 		else {
 			jsonResult = new JSONObject(result);
 		}
 		
 		String checkpoint;
		switch (caseName) {
		case "LoginSuccess":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Success");	//接口返回状态为Success
			break;
		case "PasswordError":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Fail");	//接口返回状态为Fail
			break;
		case "AccountError":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Fail");	//接口返回状态为Fail
			break;
		case "UserAccountNull":	
			Assert.assertTrue(result.isEmpty());	//接口返回是否为空
			break;
		case "PasswordNull":
			checkpoint = jsonResult.getString("Loginstatus");
			Assert.assertEquals(checkpoint,"Fail");	//接口返回状态为Fail
			break;
		default:
			break;
		}
     }
}
